﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WFNetLib.USB.HID;

namespace 脂肪仪
{
    public class zfyUSB : HIDDevice
    {
        public bool CheckDevice()
        {
            InteractionData tx = new InteractionData(0x33);
            byte[] rxb = DeviceInteraction(tx.GetDataList());
            InteractionData rx = new InteractionData(rxb);
            
            return true;
        }
    }
    public class InteractionData
    {
        public byte codeID;
        public byte[] buff = new byte[0x40];
        public int buffLen;
        public InteractionData()
        {
            buffLen = 0;
        }
        public InteractionData(byte _codeID)
        {
            codeID = _codeID;
            buffLen = 0;
        }
        public InteractionData(byte[] pBuf)
        {
            for (int i = 0; i < pBuf.Length; i++)
            {
                buff[i] = pBuf[i];
            }
            buffLen = pBuf.Length;
        }
        public byte[] GetDataList()
        {
            byte[] list = new byte[65];
            list[0] = 0x00;
            list[1] = 0xaa;
            list[2] = 0xaa;
            list[3] = codeID;
            if (buffLen == 0)
            {
                list[4] = 0;
                list[5] = 0x55;
                list[6] = 0x55;
            }
            else
            {
                for (int i = 0; i < buffLen; i++)
                {
                    list[i + 4] = buff[i];
                }
                list[4 + buffLen] = 0x55;
                list[4 + buffLen+1] = 0x55;
            }            
            return list;
        }
    }
}
